package com.ohuang.fakescreen

import android.content.Intent
import android.content.pm.ActivityInfo
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.ohuang.fakescreen.window.BlackButtonSmallWindow
import com.ohuang.fakescreen.window.BlackSmallWindow
import com.ohuang.fakescreen.window.OrientationSmallWindow

class IndexActivity : AppCompatActivity() {

    private val blackButtonSmallWindow = BlackButtonSmallWindow(this)
    private val blackSmallWindow = BlackSmallWindow(this)
    private var orientationSmallWindow= OrientationSmallWindow(this)
    private var powerKeyObserver = PowerKeyObserver(this)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_index)
        findViewById<View>(R.id.btn_1).setOnClickListener {
            startActivity(Intent(this@IndexActivity, MainActivity::class.java))
        }
        findViewById<View>(R.id.btn_2).setOnClickListener {
            if (!blackButtonSmallWindow.isShow()) {
                blackButtonSmallWindow.showSmallWindow()
            } else {
                blackButtonSmallWindow.hideSmallWindow()
                blackSmallWindow.hideSmallWindow()
            }
        }
        findViewById<View>(R.id.btn_3).setOnClickListener {

            if (orientationSmallWindow.isShow()){
                orientationSmallWindow.hideSmallWindow()
            }else{
                orientationSmallWindow.showSmallWindow()
            }
        }
        initWindows()
        powerKeyObserver.startListen()
        powerKeyObserver.setHomeKeyListener {
            blackSmallWindow.hideSmallWindow()
        }

    }



    private fun initWindows(){
        orientationSmallWindow.init(this)
        blackButtonSmallWindow.init(this)
        blackSmallWindow.init(this)
        blackButtonSmallWindow.callBack={
            blackSmallWindow.showSmallWindow()
        }
    }


    override fun onDestroy() {
        super.onDestroy()
        orientationSmallWindow.hideSmallWindow()
        blackSmallWindow.hideSmallWindow()
        blackButtonSmallWindow.hideSmallWindow()
        powerKeyObserver.stopListen()
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        SmallWindowsHelper.onActivityResult(this, requestCode, resultCode, data)
    }


}